import Taro from '@tarojs/taro'
import app from '../../../../main.js'
let myJs = {
    getData: function() {
        this.state = {
            generalIncome:Number,
            income_rocordss: {
                items: [
                     // {
                     //    id: '',
                     //    order_type: '',
                     //    desc: '',
                     //    totalpayable: '',
                     //    money: '',
                     //    status: '',
                     //    created_at: '',
                     //  }
                ]
            },
            dateSel:''
        };
        return this.state;
    },
    listIncomeRocords() {
        var me = this;
        var flag = true;
        if(me.beforeListIncomeRocords) {
            flag = me.beforeListIncomeRocords(data);
        }
        if(flag) {
            let date = new Date()
            let hour = date.getFullYear()
            let month = date.getMonth() + 1
            let data = {offset: this.offset, length: this.length, year: hour, month: month};
            app.post("web/wallet/transactionRecord", data, function(res) {
                console.log("asd",res.data.result.generalIncome)
                let generalIncome = res.data.result.generalIncome
                var dataArr = [];
                for(var i = 0; i < res.data.result.result.length; i++) {
                    var m = {
                        id: res.data.result.result[i].id,
                        order_type: res.data.result.result[i].order_type,
                        desc: res.data.result.result[i].desc,
                        totalpayable: res.data.result.result[i].totalpayable,
                        money: res.data.result.result[i].money,
                        status: res.data.result.result[i].status,
                        created_at: res.data.result.result[i].created_at,
                    }
                    dataArr.push(m);
                }
                me.setState({income_rocordss:{items: dataArr},generalIncome:generalIncome});
                if(me.afterListIncomeRocords) {
                    me.afterListIncomeRocords(res);
                }
            });
        }
    },
    componentWillMount () {
        if(this.init) {
            this.init();
        }
    },
    navigateTo(url) {
        app.navigateTo(url);
    },
    handleChange(name, v) {
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }
        temp[names[i]] = v;
        this.setState({n: temp[names[i]]});
    },
    handleTextareaChange(name, e) {
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }
        temp[names[i]] = e.target.value;
        this.setState({n: temp[names[i]]});
    },
    redirectTo(url) {
        app.redirectTo(url);
    },
    componentDidMount () {
        this.listIncomeRocords()
    },
    componentWillUnmount () {},
    componentDidHide () {}
}
export default myJs;
